package com.sumainfor.pc.market.service;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.market.dao.RdBankMapper;
import com.sumainfor.pc.market.dao.RdOwnerMapper;
import com.sumainfor.pc.market.dao.RdPactMapper;
import com.sumainfor.pc.market.feign.Zfeign.ZpcGmioFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 业主
 */
@Service
public class RdOwnerService implements Serializable {

    private ReentrantLock lock = new ReentrantLock(false);

    Logger log = LoggerFactory.getLogger(RdOwnerService.class);// 日志

    @Autowired
    private RdOwnerMapper rdOwnerMapper;
    @Autowired
    private RdPactMapper rdPactMapper;
    @Autowired
    private ZpcGmioFeign zpcGmioFeign;
    /**
     * 查询房源与业主的合同截止时间
     */
    public JsonResult getTimeCountOwner(Map<String,Object> params){
        JsonResult result=new JsonResult();
        if (params.get("HouId")==null || params.get("PaId")==null || params.get("EndTime")==null){
            return result.putFailed("参数不正确");
        }
        Map<String,Object> map=rdOwnerMapper.getTimeCountOwner(params);
        //查询这份合同是否发起过续签
        Integer PactCount = rdPactMapper.getRdRenPactCount(params);
        if (PactCount == null) {
            map.put("PactCount", 0);
        } else {
            map.put("PactCount", PactCount);
        }
        //到运营部查询房源发起过延期
        JsonResult gmioResult=zpcGmioFeign.getDiDaCount(params);
        if (gmioResult.get("errorCode")!=null && gmioResult.get("errorCode").toString().equals("0")){
            Integer DaCount=(Integer) gmioResult.get("result");
            if (DaCount==null){
                map.put("DaCount",0);
            }else{
                map.put("DaCount",DaCount);
            }
        }else{
            return result.putFailed("运营部服务器繁忙");
        }
        if (map!=null){
            result.put(map);
        }else{
            result.putFailed("服务器繁忙");
        }
        return result;
    }
}
